package com.example.picture;

import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    Button btn_start, btn_stop;
    ImageView iv;

    Button lastPic,nextPic,showMusic;
    public Animation mAnimation;
    int count = 0;
    int[] imgRes = {R.drawable.bbb1,R.drawable.bbb2,R.drawable.bbb3,R.drawable.bbb4,R.drawable.bbb5,R.drawable.bbb6};
    //    音乐部分
    private MediaPlayer mediaPlayer;
    private SeekBar seekBar;
    private boolean playFlag = false,pauseFlag = false;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        绑定按钮 第一批
        iv = findViewById(R.id.ViewWIN);
        btn_start = findViewById(R.id.star);
        btn_stop = findViewById(R.id.stop);
//        第二批
        lastPic = findViewById(R.id.LastPic);
        nextPic = findViewById(R.id.nextPic);
        showMusic = findViewById(R.id.Show_ALL);
//        第三层 音乐部分
        seekBar = (SeekBar)this.findViewById(R.id.seekBar);
        mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.my_music);




//
        btn_start.setOnClickListener(this);
        btn_stop.setOnClickListener(this);
//
        lastPic.setOnClickListener(this);
        nextPic.setOnClickListener(this);
        showMusic.setOnClickListener(this);

        Bitmap bm = BitmapFactory.decodeResource(this.getResources(),imgRes[count]);
        iv.setImageBitmap(bm);

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.star:
                //设置图片资源
                iv.setImageResource(R.drawable.my_frameanimation);
                //获取动画对象
                AnimationDrawable start = (AnimationDrawable) iv.getDrawable();
                //开启
                start.start();
                break;
            case R.id.stop:
                //获取动画对象
                AnimationDrawable stop = (AnimationDrawable) iv.getDrawable();
                //关闭动画
                stop.stop();
                iv.stopNestedScroll();
                break;
            case R.id.LastPic:
                mAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.my_all);
                iv.startAnimation(mAnimation);


                if (count != 0){count = count-1;}
                Bitmap bm = BitmapFactory.decodeResource(MainActivity.this.getResources(),imgRes[count]);
                iv.setImageBitmap(bm);
                break;
            case R.id.nextPic:
                mAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.my_all);
                iv.startAnimation(mAnimation);

                count++;
                if (count == 6){count = 0;}
                bm = BitmapFactory.decodeResource(MainActivity.this.getResources(), imgRes[count]);
                iv.setImageBitmap(bm);
                break;
            case R.id.Show_ALL:
                mAnimation = AnimationUtils.loadAnimation(MainActivity.this,R.anim.my_all);
                iv.startAnimation(mAnimation);
                //音乐部分
                if(pauseFlag==false) {

                }

                //设置图片资源
                iv.setImageResource(R.drawable.my_frameanimation2);
                //获取动画对象
                start = (AnimationDrawable) iv.getDrawable();
                //开启
                start.start();
                break;
        }
    }
}